package com.michael.study.component.service

import android.app.Service
import android.content.Intent
import android.os.*
import android.util.Log

/**
 * Description:
 *
 * Created by liuguoquan on 2020/8/3 16:17.
 */
class MessengerService : Service() {

    private class MessengerHandler : Handler() {

        override fun handleMessage(msg: Message) {
            when (msg.what) {
                1000 -> {
                    Log.d("lgq", "receive a msg from client")
                    var client = msg.replyTo
                    var msg = Message.obtain(null, 2000)
                    try {

                        client.send(msg)
                    } catch (e : RemoteException) {

                    }
                }
            }
        }
    }

    private var mMessenger = Messenger(MessengerHandler())

    override fun onBind(intent: Intent?): IBinder? {
        return mMessenger.binder
    }
}